package com.flying.flow.service;

import java.util.Date;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.annotation.Transaction;
import com.flying.common.util.Codes;
import com.flying.common.util.DateUtils;
import com.flying.common.util.DateUtils.Field;
import com.flying.flow.model.FlowInstance;
import com.flying.flow.model.Node;
import com.flying.flow.model.Node.AllowSplit;
import com.flying.flow.model.Node.EmergencyLevel;
import com.flying.flow.model.Node.PriorityLevel;
import com.flying.flow.model.NodeInstance;
import com.flying.flow.model.Task;
import com.flying.flow.model.Task.DealResult;
import com.flying.flow.model.Task.TaskStatus;
import com.flying.flow.util.FlowUtils;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.context.ServiceContext;
import com.flying.framework.data.Data;
import com.flying.framework.exception.AppException;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.model.QueryResult;
import com.flying.framework.security.Principal;
import com.flying.framework.service.AbstractService;

@Service(value="TaskService", desc="工作任务")
public class TaskService extends AbstractService{
	private FlowInstanceService fis;
	private NodeInstanceService nis;
	private NodeService ns;
	
	public void setFlowInstanceService(FlowInstanceService s) {
		this.fis = s;
	}
	public void setNodeInstanceService(NodeInstanceService s) {
		this.nis = s;
	}
	
	public void setNodeService(NodeService s) {
		this.ns = s;
	}
	
	@MethodInfo("新增")
	public Task createByNodeInstance(
			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String orgCode,
			@Param(value=Task.BUSINESS_TYPE, required=true,	desc="业务类型") String businessType,
			@Param(value=Task.BUSINESS_CODE, required=true,	desc="业务代码") String businessCode,
			@Param(value=Task.PARTICIPANT_ID, required=false,	desc="执行人") String participant_id,
			@Param(value="NodeInstance", required=true,	desc="节点实例")NodeInstance ni) throws Exception {
		Date plan_start = new Date();
		Date plan_end = DateUtils.add(plan_start, Field.SECOND, FlowUtils.parseExpectTimeAsSeconds(ni.getExpectTime()));
		Node n = this.ns.findById(ni.getNodeId());
		FlowInstance fi = this.fis.findById(ni.getFlowInstanceId());
		
		return this.create(null, ni.getNodeId(), ni.getNodeInstanceId(), ni.getFlowId(), ni.getFlowDefId(), ni.getFlowInstanceId(), 
				fi.getOrderNo(), ni.getName(), ni.getRemarks(), TaskStatus.ASSIGNING.value(), 
				orgCode, businessType, businessCode, null, ni.getEmergencyLevel(), ni.getPriorityLevel(), n.getAllowSplit(),
				ni.getFormAction(), ni.getFormCode(), ni.getFormData(),
				participant_id, plan_start, plan_end, DealResult.PROCESSING.value(), null, null);
	}
	
	@MethodInfo("新增")
	@DaoCreate(entity=Task.ENTITY_NAME)
	public Task create(
			@Param(value=Task.PARENT_ID, required=false,	desc="父级任务ID") Long parent_id,
			@Param(value=Task.NODE_ID, required=true,	desc="节点ID") Long node_id,
			@Param(value=Task.NODE_INSTANCE_ID, required=true,	desc="节点实例ID") Long node_instance_id,
			@Param(value=Task.FLOW_ID, required=true,	desc="流程ID") Long flow_id,
			@Param(value=Task.FLOW_DEF_ID, required=true,	desc="流程定义ID") Long flow_def_id,
			@Param(value=Task.FLOW_INSTANCE_ID, required=true,	desc="流程实例ID") Long flow_instance_id,

			@Param(value=Task.ORDER_NO, required=true,	desc="工单号") String order_no,
			@Param(value=Task.NAME, required=true,	desc="名称") String name,
			@Param(value=Task.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,

			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String org_code,
			@Param(value=Task.BUSINESS_TYPE, required=true,	desc="业务类型") String business_type,
			@Param(value=Task.BUSINESS_CODE, required=true,	desc="业务代码") String business_code,
			@Param(value=Task.SUB_BUSINESS_CODE, required=false,	desc="子业务代码") String sub_business_code,
			@Param(value=Task.EMERGENCY_LEVEL, required=false, enumClass=EmergencyLevel.class,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false,enumClass=PriorityLevel.class,	desc="优先级别") Integer priority_level,
			@Param(value=Node.ALLOW_SPLIT, required=true, enumClass=AllowSplit.class,	desc="允许拆分任务") Integer allow_split,

			@Param(value=Task.FORM_ACTION, required=false,	desc="表单行为") String form_action,
			@Param(value=Task.FORM_CODE, required=false,	desc="表单代码") String form_code,
			@Param(value=Task.FORM_DATA, required=false,	desc="表单数据") String form_data,
			
			@Param(value=Task.PARTICIPANT_ID, required=false,	desc="执行人") String participant_id,
			@Param(value=Task.PLAN_START, required=false,	desc="计划开始时间") Date plan_start,
			@Param(value=Task.PLAN_END, required=false,	desc="计划结束时间") Date plan_end,
			@Param(value=Task.DEAL_RESULT, required=false, enumClass=DealResult.class,	desc="处理结果") Integer dealResult,
			@Param(value=Task.CREATE_TIME, required=false,	desc="创建时间") Date create_time,
			@Param(value=Task.CREATOR, required=false,	desc="创建人") String creator
		
		) throws Exception {
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(Task.class, 
				Task.CREATOR, (p == null?null: p.getName()),
				Task.CREATE_TIME, new Date());
	}

	@MethodInfo("分配任务")
	@DaoUpdate(entity=Task.ENTITY_NAME)
	public ActionResult assign(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=Task.EMERGENCY_LEVEL, required=false, enumClass=EmergencyLevel.class,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false,enumClass=PriorityLevel.class,	desc="优先级别") Integer priority_level,
			@Param(value=Task.PLAN_START, required=false,	desc="计划开始时间") Date plan_start,
			@Param(value=Task.PLAN_END, required=false,	desc="计划结束时间") Date plan_end,
			@Param(value=Task.PARTICIPANT_ID, required=true,	desc="执行人") String participant_id,
			
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.UPDATOR, required=false,	desc="修改人") String updator,
			@Param(value=Task.UPDATE_TIME, required=false,	desc="修改时间") Date update_time) throws Exception {
		Task t = this.findById(task_id);
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(ActionResult.class, 
				Task.EMERGENCY_LEVEL, emergency_level == null?t.getEmergencyLevel(): emergency_level,
				Task.PRIORITY_LEVEL, priority_level == null?t.getPriorityLevel(): priority_level,
				Task.PLAN_START, plan_start == null?t.getPlanStart(): plan_start,
				Task.PLAN_END, plan_end == null?t.getPlanEnd(): plan_end,
				
				Task.STATUS, TaskStatus.ASSIGNED.value(),
				Task.UPDATOR, (p == null?null: p.getName()),
				Task.UPDATE_TIME, new Date());
	}

	@MethodInfo("分配任务")
	@DaoUpdate(entity=Task.ENTITY_NAME)
	public ActionResult start(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=Task.PARTICIPANT_ID, required=true,	desc="执行人") String participant_id,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.ACTUAL_START, required=false,	desc="实际开始时间") Date actual_start,
			@Param(value=Task.UPDATOR, required=false,	desc="修改人") String updator,
			@Param(value=Task.UPDATE_TIME, required=false,	desc="修改时间") Date update_time) throws Exception {
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(ActionResult.class, 
				Task.STATUS, TaskStatus.PROCESSING.value(),
				Task.ACTUAL_START, new Date(),
				Task.UPDATOR, (p == null?null: p.getName()),
				Task.UPDATE_TIME, new Date());
		
	}
	
	@MethodInfo("分解任务")
	public Task split(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=Task.NAME, required=true,	desc="名称") String name,
			@Param(value=Task.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Task.SUB_BUSINESS_CODE, required=true,	desc="子业务代码") String subBusinessCode,
			@Param(value=Task.EMERGENCY_LEVEL, required=false, enumClass=EmergencyLevel.class,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false, enumClass=PriorityLevel.class, desc="优先级别") Integer priority_level,
			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String orgCode,
			@Param(value=Task.PARTICIPANT_ID, required=true,	desc="执行人") String participant_id,
			@Param(value=Task.PLAN_START, required=false,	desc="计划开始时间") Date plan_start,
			@Param(value=Task.PLAN_END, required=false,	desc="计划结束时间") Date plan_end) throws Exception {
		Task t = this.findById(task_id);
		if(t.getParentId() != null) {
			throw new AppException("0101", t.getName()+"是子任务，不能继续分解！");
		}
		Node n = this.ns.findById(t.getNodeId());
		if(t.getAllowSplit() != AllowSplit.ALLOW.value()) {
			throw new AppException("0101", n.getName()+"被定义为不能继续分解！");
		}
		NodeInstance ni = this.nis.findById(t.getNodeInstanceId());
		plan_start = plan_start == null?new Date() : plan_start;
		plan_end = plan_end == null?DateUtils.add(plan_start, Field.SECOND, FlowUtils.parseExpectTimeAsSeconds(ni.getExpectTime())) : plan_end;

		FlowInstance fi = this.fis.findById(ni.getFlowInstanceId());
		
		return this.create(task_id, t.getNodeId(), t.getNodeInstanceId(), t.getFlowId(), t.getFlowDefId(), t.getFlowInstanceId(), 
				fi.getOrderNo(), name == null?t.getName() : name, remarks == null? t.getRemarks(): remarks, TaskStatus.ASSIGNING.value(), 
				orgCode, t.getBusinessType(), t.getBusinessCode(), subBusinessCode, emergency_level == null?t.getEmergencyLevel() : emergency_level, priority_level == null? t.getPriorityLevel() : priority_level, t.getAllowSplit(), 
				t.getFormAction(), t.getFormCode(), t.getFormData(),
				participant_id, plan_start, plan_end, DealResult.PROCESSING.value(), null, null);
	}
	
	@MethodInfo("提交任务")
	@Transaction
	public ActionResult commit(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=Task.CONTENT, required=true,	desc="提交内容") String content,
			@Param(value=Task.DEAL_RESULT, required=false, enumClass=DealResult.class,	desc="处理结果") Integer dealResult,
			@Param(value=Task.FORM_DATA, required=false,	desc="表单数据") Data form_data) throws Exception {
		Task t = this.findById(task_id);
		if(form_data == null) form_data = new Data();
		form_data.put(Task.TASK_ID, task_id);
		form_data.put(Task.DEAL_RESULT, dealResult);
		Data d = FlowUtils.process(t.getFormAction(), form_data);
		return this.commit2(task_id, TaskStatus.FINISHED.value(), new Date(), content, dealResult, 
				t.getFormAction(), t.getFormCode(), d == null?null:d.toString(), null, null);
	}
	
	@MethodInfo("提交任务")
	@DaoUpdate(entity=Task.ENTITY_NAME)
	protected ActionResult commit2(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.ACTUAL_END, required=false,	desc="实际结束时间") Date actual_end,
			@Param(value=Task.CONTENT, required=true,	desc="提交内容") String content,
			@Param(value=Task.DEAL_RESULT, required=false, enumClass=DealResult.class,	desc="处理结果") Integer dealResult,
			@Param(value=Task.FORM_ACTION, required=false,	desc="表单行为") String form_action,
			@Param(value=Task.FORM_CODE, required=false,	desc="表单代码") String form_code,
			@Param(value=Task.FORM_DATA, required=false,	desc="表单数据") String form_data,
			@Param(value=Task.UPDATOR, required=false,	desc="修改人") String updator,
			@Param(value=Task.UPDATE_TIME, required=false,	desc="修改时间") Date update_time) throws Exception {
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(ActionResult.class, 
				Task.UPDATOR, (p == null?null: p.getName()),
				Task.UPDATE_TIME, new Date());
	}

	@MethodInfo("取消任务")
	@DaoUpdate(entity=Task.ENTITY_NAME)
	public ActionResult cancel(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,
			
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.UPDATOR, required=false,	desc="修改人") String updator,
			@Param(value=Task.UPDATE_TIME, required=false,	desc="修改时间") Date update_time) {
		Task t = this.findById(task_id);
		if(t.getStatus() == TaskStatus.FINISHED.value() || t.getStatus() == TaskStatus.CANCELED.value()) {
			throw new AppException("0101","已结束和已取消的任务不能取消");
		}
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(ActionResult.class, 
				Task.STATUS, TaskStatus.CANCELED.value(),
				Task.UPDATOR, (p == null?null: p.getName()),
				Task.UPDATE_TIME, new Date());
	}
	
	@MethodInfo("修改")
	@DaoUpdate(entity=Task.ENTITY_NAME)
	public ActionResult update(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,

			@Param(value=Task.NAME, required=true,	desc="名称") String name,
			@Param(value=Task.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,

			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String orgCode,
			@Param(value=Task.BUSINESS_TYPE, required=true,	desc="业务类型") String businessType,
			@Param(value=Task.BUSINESS_CODE, required=true,	desc="业务代码") String businessCode,
			@Param(value=Task.SUB_BUSINESS_CODE, required=false,	desc="子业务代码") String subBusinessCode,
			@Param(value=Task.EMERGENCY_LEVEL, required=false, enumClass=EmergencyLevel.class,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false, enumClass=PriorityLevel.class, desc="优先级别") Integer priority_level,

			@Param(value=Task.PARTICIPANT_ID, required=false,	desc="执行人") String participant_id,
			@Param(value=Task.PLAN_START, required=false,	desc="计划开始时间") Date plan_start,
			@Param(value=Task.PLAN_END, required=false,	desc="计划结束时间") Date plan_end,
			@Param(value=Task.ACTUAL_START, required=false,	desc="实际开始时间") Date actual_start,
			@Param(value=Task.ACTUAL_END, required=false,	desc="实际结束时间") Date actual_end,
			@Param(value=Task.CONTENT, required=true,	desc="提交内容") String content,
			@Param(value=Task.DEAL_RESULT, required=false, enumClass=DealResult.class,	desc="处理结果") Integer dealResult,
			@Param(value=Task.UPDATOR, required=false,	desc="修改人") String updator,
			@Param(value=Task.UPDATE_TIME, required=false,	desc="修改时间") Date update_time
		) throws Exception {
		Task t = this.findById(task_id);
		if(t.getStatus() == TaskStatus.FINISHED.value() || t.getStatus() == TaskStatus.CANCELED.value()) {
			throw new AppException("0101","已结束和已取消的任务不能修改");
		}
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(ActionResult.class, 
				Task.UPDATOR, (p == null?null: p.getName()),
				Task.UPDATE_TIME, new Date());
	}
	
	@MethodInfo("修改")
	@DaoUpdate(entity=Task.ENTITY_NAME)
	public ActionResult updateTask(
			@Param(value=Task.TASK_ID, required=true,	desc="任务ID") Long task_id,

			@Param(value=Task.NAME, required=true,	desc="名称") String name,
			@Param(value=Task.REMARKS, required=false,	desc="说明") String remarks,

			@Param(value=Task.EMERGENCY_LEVEL, required=false, enumClass=EmergencyLevel.class,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false, enumClass=PriorityLevel.class, desc="优先级别") Integer priority_level,

			@Param(value=Task.PLAN_START, required=false,	desc="计划开始时间") Date plan_start,
			@Param(value=Task.PLAN_END, required=false,	desc="计划结束时间") Date plan_end,
			@Param(value=Task.ACTUAL_START, required=false,	desc="实际开始时间") Date actual_start,
			@Param(value=Task.ACTUAL_END, required=false,	desc="实际结束时间") Date actual_end,
			@Param(value=Task.UPDATOR, required=false,	desc="修改人") String updator,
			@Param(value=Task.UPDATE_TIME, required=false,	desc="修改时间") Date update_time
		) throws Exception {
		Task t = this.findById(task_id);
		if(t.getStatus() == TaskStatus.FINISHED.value() || t.getStatus() == TaskStatus.CANCELED.value()) {
			throw new AppException("0101","已结束和已取消的任务不能修改");
		}
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(ActionResult.class, 
				Task.UPDATOR, (p == null?null: p.getName()),
				Task.UPDATE_TIME, new Date());
	}

	@MethodInfo("删除")
	@DaoRemove(entity=Task.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=Task.TASK_ID, required=true,	desc="节点实例ID") Long task_id
		) throws Exception {
		return null;
	}
	
	@MethodInfo("搜索")
	public QueryResult<Task> findMyTasks(
			@Param(value=Task.NAME, required=false,	desc="名称", tag="LIKE") String name,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String orgCode,
			@Param(value=Task.BUSINESS_TYPE, required=false,	desc="业务类型") String businessType,
			@Param(value=Task.BUSINESS_CODE, required=false,	desc="业务代码") String businessCode,
			@Param(value=Task.SUB_BUSINESS_CODE, required=false,	desc="子业务代码") String subBusinessCode,
			@Param(value=Task.EMERGENCY_LEVEL, required=false,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false,	desc="优先级别") Integer priority_level,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		Principal p = ServiceContext.getContext().getPrincipal();
		return this.findAll(null, name, status, orgCode, businessType, businessCode, subBusinessCode, 
				emergency_level, priority_level, p == null?"NONE": p.getName(), page, rows);
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Task.ENTITY_NAME, pageable=true, modelClass=Task.class, osql="ORDER BY t.create_time desc")
	public QueryResult<Task> findAll(
			@Param(value=Task.FLOW_INSTANCE_ID, required=false,	desc="流程实例ID") Long flow_instance_id,
			@Param(value=Task.NAME, required=false,	desc="名称", tag="LIKE") String name,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String orgCode,
			@Param(value=Task.BUSINESS_TYPE, required=false,	desc="业务类型") String businessType,
			@Param(value=Task.BUSINESS_CODE, required=false,	desc="业务代码") String businessCode,
			@Param(value=Task.SUB_BUSINESS_CODE, required=false,	desc="子业务代码") String subBusinessCode,
			@Param(value=Task.EMERGENCY_LEVEL, required=false,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false,	desc="优先级别") Integer priority_level,
			@Param(value=Task.PARTICIPANT_ID, required=false,	desc="执行人") String participant_id,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}
	
	@SuppressWarnings("unchecked")
	@MethodInfo("搜索")
	@DaoQuery(entity=Task.ENTITY_NAME, pageable=true, modelClass=Task.class, osql="ORDER BY t.create_time desc")
	public QueryResult<Task> findSeizingTasks(
			@Param(value=Task.FLOW_INSTANCE_ID, required=false,	desc="流程实例ID") Long flow_instance_id,
			@Param(value=Task.NAME, required=false,	desc="名称", tag="LIKE") String name,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态") Integer status,
			@Param(value=Task.ORG_CODE, required=false,	desc="机构代码") String orgCode,
			@Param(value=Task.BUSINESS_TYPE, required=false,	desc="业务类型") String businessType,
			@Param(value=Task.BUSINESS_CODE, required=false,	desc="业务代码") String businessCode,
			@Param(value=Task.SUB_BUSINESS_CODE, required=false,	desc="子业务代码") String subBusinessCode,
			@Param(value=Task.EMERGENCY_LEVEL, required=false,	desc="紧急程度") Integer emergency_level,
			@Param(value=Task.PRIORITY_LEVEL, required=false,	desc="优先级别") Integer priority_level,
			@Param(value="pid2", required=false,	desc="执行人") String participant_id,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(QueryResult.class, "pid2", p.getName());
	}
	
	@MethodInfo("搜索")
	@DaoQuery(entity=Task.ENTITY_NAME, pageable=false, modelClass=Task.class)
	public QueryResult<Task> findByNodeInstanceId(
			@Param(value=Task.NODE_INSTANCE_ID, required=true,	desc="节点实例ID") Long node_instance_id,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态", tag="IN") Integer[] status) {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Task.ENTITY_NAME, pageable=false, modelClass=Task.class)
	public QueryResult<Task> findByFlowInstanceId(
			@Param(value=Task.FLOW_INSTANCE_ID, required=true,	desc="流程实例ID") Long flow_instance_id,
			@Param(value=Task.STATUS, required=false, enumClass=TaskStatus.class,	desc="状态", tag="IN") Integer[] status) {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Task.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Task findById(
			@Param(value=Task.TASK_ID, required=true,	desc="节点实例ID") Long task_id
		) {
		return null;
	}

}